﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Classes
{
    class Connection
    {
        IList<Flight> flights;
        IList<City> cities;
        City departureCity { get; set; }
        City destinationCity { get; set; }
        int totalTime { get; set; }
        int totalPrice { get; set; }
        int numberOfFlightChange { get; set; }
        int noOfseatsLeft { get; set; }
        int noOfSeatsReservedByCustomer { get; set; }
        public Connection()
        {
            flights = new List<Flight>();
            cities = new List<City>();
            //sequenceOfParentCities = new List<City>();
        }
        public IList<Flight> FlightList()
        {
            return flights;
        }
        public void SetCityList(IList<City> visited)
        {
            cities = visited;
        }
        public void SetFlightList(IList<Flight> value)
        {
            flights = value;
        }
        public void RemoveFlight(Flight flight)
        {
            flights.Remove(flight);
        }

        public void AddFlight(Flight flight)
        {
            flights.Add(flight);
        }
        public IList<Flight> MakeFlightsOfCities(IList<City> list)
        {
            //foreach (City c in list)
            //{
            //    Console.WriteLine(c.Name);
            //    Console.WriteLine(" ");
            //}
            //Console.WriteLine();
            //return null;
            for (int i = 0; i < list.Count() - 1; i++)
            {
                City c = list[i];
                City x = list[i + 1];
                Flight y = c.Flights().First(z => z.To == x);
                
               
                flights.Add(y);
            }
            SetFlightList(flights);
            Console.WriteLine();
            
            return flights;
        }
        public void Print()
        {
            foreach(Flight f in flights)
            {
                Console.WriteLine(f.From.Name + " ---> " + f.To.Name);

            }
        }
        public IList<City> CitiesList()
        {
            return cities;
        }

    }
}
